<?xml version="1.0"?>
<properties>
  <include buildfile="thirdparty.binaries.xml" />
  <include buildfile="func.msbuild2.xml" />


  <property name="nunit.unittest" value="true" />
  <property name="nunit.buildtest" value="true" />
  <property name="tools.nunit.path" value="${tools.path}\nunit" />



  <target name="nunit">
    <call target="nunit-init-variables" />
    <if test="${nunit.buildtest}">
      <call target="nunit-build" />
    </if>
    <call target="nunit-test" />
    <!--<delete dir="${dest.test.path}" />-->
  </target>

  <target name="nunit-org">
    <call target="nunit-init-variables" />
    <if test="${nunit.buildtest}">
      <call target="nunit-build" />
    </if>
    <call target="nunit-org-test" />
    <!--<delete dir="${dest.test.path}" />-->
  </target>


  <target name="nunit-init-variables">
    <property name="nunit.test.name" value="${project::get-name()}.IntegrationTest" />
    <property name="nunit.src.path" value="${src.test.path}${nunit.test.name}\" />
    <if test="${nunit.unittest}">
      <property name="nunit.test.name" value="${project::get-name()}.UnitTest" />
      <property name="nunit.src.path" value="${src.test.path}${nunit.test.name}\" />
    </if>
    <property name="nunit.src.csproj" value="${nunit.src.path}${nunit.test.name}.csproj" />

    <property name="nunit.test.bin" value="${nunit.test.name}.dll" />
    <property name="dest.test.path" value="${dest.test.path}" />
  </target>

  <target name="nunit-build">
    <call target="nunit-init-variables" />
    
    <echo message="copy: ${lib.path} --> ${dest.test.path}" />
    <copy todir="${dest.test.path}\">
      <fileset basedir="${lib.path}">
        <include name="*" />
        <exclude name="COFE.*" />
        <include name="${thirdparty.nunitframework}.dll" />
      </fileset>
    </copy>
    

    <echo message="build.test: ${nunit.test.bin}" />
    <echo message="build.test: ${nunit.src.path}" />
    
    <property name="msbuild.csproj.path" value="${nunit.src.csproj}" />
    <property name="msbuild.version" value="45" />
    <call target="msbuild" />

    <echo message="copy: ${dest.current.path} --> ${dest.test.path}" />
    <copy todir="${dest.test.path}\">
      <fileset basedir="${dest.current.path}">
        <include name="*" />
        <exclude name="COFE.*" />
      </fileset>
    </copy>
    
   
    <!--<csc target="library" output="${dest.test.path}\${nunit.test.bin}"
         debug="${debug}" unsafe="false" platform="x86" >
      <references>
        <include name="System.Data.Entity.dll" />
        <include name="${dest.test.path}\*.dll" />
        <exclude name="${dest.test.path}\${thirdparty.sevenzip}.dll" />
        <exclude name="${dest.test.path}\${thirdparty.sevenzip64}.dll" />
      </references>
      <sources>
        <include name="${nunit.src.path}\**.cs" />
      </sources>      
    </csc>-->

    <echo message="${nunit.src.path}\app.config -> ${dest.test.path}\${nunit.test.bin}.config" />
    <copy failonerror="false"
     file="${nunit.src.path}\app.config"
     tofile="${dest.test.path}\${nunit.test.bin}.config" />
  </target>

  <target name="nunit-test">
    <echo message="test: ${dest.test.path}\${nunit.test.bin}" />

    <!-- Run Unit Tests under NUnit 2.5 -->
    <exec program="${tools.nunit.path}\nunit-console-x86.exe"
          workingdir="${dest.test.path}"
          >
      <arg value="${nunit.test.bin}" />
    </exec>

    <!--<nunit2>
      <formatter type="Plain" />      
      <test assemblyname="${dest.test.path}\${nunit.test.bin}" />
    </nunit2>-->
  </target>

  <target name="nunit-org-test">
    <echo message="test: ${dest.test.path}\${nunit.test.bin}" />

    <nunit2>
      <formatter type="Plain" />
      <test assemblyname="${dest.test.path}\${nunit.test.bin}" />
    </nunit2>
  </target>

</properties>